package com.hzhc.controller.sysmanage;

import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.SysOrganization;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.SysOrganizationService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.TreeVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 组织机构
 *
 * @author 功不唐捐
 * @since 2024-04-07
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/organization")
public class SysOrganizationController extends BaseController {

    private final SysOrganizationService organizationService;

    /**
     * 获取树形菜单
     */
    @RequestMapping("/getOrganizationTree")
    public ResultUtil<List<TreeVo>> getOrganizationTree(@RequestBody SysOrganization vo) {
        Long pid = vo.getPid() == null ? 0 : vo.getPid();
        return ResultUtil.build(organizationService.getOrganizationTree(pid), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 获取组织机构列表
     */
    @RequestMapping("/getOrganizationList")
    public ResultUtil<List<SysOrganization>> getMenuList(@RequestBody SysOrganization vo) {
        return ResultUtil.build(organizationService.getOrganizationListAll(vo), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 组织机构增加
     */
    @PostMapping("/saveOrganization")
    @SysTemLog(operModul = "系统管理-组织机构新增", operType = "新增", operDesc = "组织机构新增功能", modular = "PC")
    public ResultUtil<T> saveMenu(@RequestBody SysOrganization vo) {
        vo.setPid(vo.getPid() == null ? 0L : vo.getPid());
        return organizationService.saveOrganization(vo);
    }

    /**
     * 组织机构修改
     */
    @PostMapping("/updateOrganization")
    @SysTemLog(operModul = "系统管理-组织机构修改", operType = "修改", operDesc = "组织机构修改功能", modular = "PC")
    public ResultUtil<T> updateMenu(@RequestBody SysOrganization vo) {
        vo.setPid(vo.getPid() == null ? 0L : vo.getPid());
        return organizationService.updateOrganization(vo);
    }

    /**
     * 组织机构校验
     */
    @PostMapping("/checkOrg")
    public ResultUtil<T> checkOrg(@RequestBody SysOrganization vo) {
        return organizationService.checkOrg(vo);
    }

    /**
     * 组织机构删除
     */
    @RequestMapping("/deleteOrg")
    @SysTemLog(operModul = "系统管理-组织机构删除", operType = "删除", operDesc = "组织机构删除功能", modular = "PC")
    public ResultUtil<T> deleteOrg(@RequestBody SysOrganization vo) {
        return organizationService.deleteOrg(vo);
    }

}
